package projet.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import projet.entity.Course;
import projet.entity.Session;
import projet.service.DescriptionService;

/**
 * Servlet implementation class DescriptionServlet
 */
public class DescriptionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private DescriptionService descriptionService = new DescriptionService();
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DescriptionServlet() {
        super();
        // Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String courseCode = request.getParameter("code");
		Course course = descriptionService.getCourse(courseCode);
		//List<Session> sessions = descriptionService.getSessions(course);
		List<Session> sessions = descriptionService.getSessionsFuture(course);

		request.setAttribute("course", course);
		request.setAttribute("sessions", sessions);
		RequestDispatcher dispatcher = request.getRequestDispatcher("description.jsp");
		dispatcher.forward(request, response);
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// Auto-generated method stub
	}

}
